<script setup>
import {ref} from 'vue'
// 通过 defineProps 编译器宏接收父组件传递的数据
const parentMessage = defineProps({
  message: String
})
console.log(parentMessage.message)

const count = ref(1)
// 通过 defineEmits 编译器宏生成emit方法必须先声明 发送给父组件的方法
const emit = defineEmits(['changeCount','changeMessages'])
const changeCounts = () => {
  emit('changeCount', count.value++)
}

const sonChangeMessage = ()=>{
  emit('changeMessages', parentMessage.message+'子组件')
}
</script>

<template>
  <div class="son-component">
    {{ message }}
    <hr>
    <button @click="changeCounts">修改count传给父组件</button>
    <hr>
    <button @click="sonChangeMessage">修改父组件传的值</button>
  </div>
</template>

<style scoped>

</style>
